$MU.setContext($CONTEXT)##
#set($TYPE = $model.name)
#set($type = $CSU.getVariable($TYPE))
#set($idField = $MU.getIdField($model))
#set($IdType = $idField.type)
#set($modelName = $model.name)
#if($model.package)
#set($modelName = $model.package+'.'+$model.name)
#end
#set($modelLabel = $model.name)
#if($model.label)#set($modelLabel = $model.label)#end
##
#macro(label $obj)
	#if($obj.label)$obj.label#else$obj.name#end
#end
##
#macro(Column $field)
	#replace("\s+"," ")
		#set($colText = '')
		#if($TU.isNotNull($field.nullable) && !$field.nullable)
			#set($colText = $colText+', nullable='+$field.nullable)
		#end
		#if($TU.isNotNull($field.length))
			#set($colText = $colText+', length='+$field.length)
		#end
		#if($field.unique)
			#set($colText = $colText+', unique='+$field.unique)
		#end
		#if($colText.length()>0)
			#set($colText = '@Column('+$colText.substring(1)+')')
			$colText
		#end
	#end
#end
##
#macro(id $model, $field)
	#if($field.id)
		@Id
		@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "g")
		@SequenceGenerator(name = "g", sequenceName = "seq_${model.name}", allocationSize = 1)
	#end
#end
##
#macro(fieldAnno $model, $field)
#trim('eachrow', 1, 'rn')
	#if($field.version)
		@Version
	#end

	#if($field.transient)
		@Transient
	#end

	#id($model, $field)

	#Column($field)
#end
#end
##
#macro(refParams $model, $startParam)
#replace("\s{2,}","")
	#set($paramStr = '')
	#set($refFieldLst = $MU.getReferenceFields($model))
	#foreach($field in $refFieldLst)
		#set($paramStr = $paramStr + ', '+$field.type+' '+$field.name)
	#end
	#if($paramStr.length()>0 && $startParam)
		#set($paramStr = $paramStr.substring(2))
	#end
	$paramStr #*display*#
#end
#end
##
#macro(refParamVals $model, $startParam)
#replace("\s{2,}","")
	#set($paramStr = '')
	#set($haveKeyword = false)
	#set($refFieldLst = $MU.getReferenceFields($model))
	#foreach($field in $refFieldLst)
		#if($field.type=='Date')
			#set($paramStr = $paramStr + ', '+$field.name+'Start')
			#set($paramStr = $paramStr + ', '+$field.name+'End')
		#elseif(!$field.id && $MU.isPrimitive($field.type))
			#set($paramStr = $paramStr + ', '+$field.name)
		#end

		#if($field.type=='String')
			#set($haveKeyword = true)
		#end
	#end
	#if($haveKeyword)
		#set($paramStr = $paramStr + ', keyword')
	#end

	#if($paramStr.length()>0 && $startParam)
		#set($paramStr = $paramStr.substring(2))
	#end
	$paramStr #*display*#

#end
#end
##
#macro(allParams $model, $startParam, $Inherit)
#replace("\s{2,}","")
	#set($paramStr = '')
	#set($haveKeyword = false)
	#if($Inherit)
		#set($allFields = $MU.findAllField($model, true))
	#else
		#set($allFields = $MU.getSortedList($model.fields))
	#end
	#foreach($field in $allFields)
		#if($field.type=='Date')
			#set($paramStr = $paramStr + ', '+$field.type+' '+$field.name+'Start')
			#set($paramStr = $paramStr + ', '+$field.type+' '+$field.name+'End')
		#elseif(!$field.id && $MU.isPrimitive($field.type))
			#set($paramStr = $paramStr + ', '+$field.type+' '+$field.name)
		#end

		#if($field.type=='String')
			#set($haveKeyword = true)
		#end
	#end
	#if($haveKeyword)
		#set($paramStr = $paramStr + ', String keyword')
	#end

	#if($paramStr.length()>0 && $startParam)
		#set($paramStr = $paramStr.substring(2))
	#end
	$paramStr #*display*#

#end
#end
##
#macro(allParamVals $model)
#replace("\s{2,}","")
	#set($paramStr = '')
	#set($haveKeyword = false)
	#set($allFields = $MU.getSortedList($model.fields))
	#foreach($field in $allFields)
		#if($field.type=='Date')
			#set($paramStr = $paramStr + ', '+$field.name+'Start')
			#set($paramStr = $paramStr + ', '+$field.name+'End')
		#elseif(!$field.id && $MU.isPrimitive($field.type))
			#set($paramStr = $paramStr + ', '+$field.name)
		#end

		#if($field.type=='String')
			#set($haveKeyword = true)
		#end
	#end
	#if($haveKeyword)
		#set($paramStr = $paramStr + ', keyword')
	#end

	#if($paramStr.length()>0 && $startParam)
		#set($paramStr = $paramStr.substring(2))
	#end
	$paramStr #*display*#

#end
#end
##
#macro(importOtherEntity $model)
#trim('eachrow', 0, 'rn')
	#set($typeList = $MU.getImportList($model))
	#foreach($type in $typeList)
		#if($type && !$type.startsWith("java.lang."))
			import $type;
		#end
	#end
#end
#end
##
#macro(delRelation)
	#set($mtmList = $MU.findMtmList($model, $modelName))
	#foreach($mtm in $mtmList)
		#set($RelationItem = $CSU.getSimpleType($mtm.relation))
		#set($relationItem = $CSU.getVariable($RelationItem))
		#set($relationKey = $mtm.relationKey)
		this.${relationItem}DAO.deleteByProperty("${relationKey}", ${type}.getId());

	#end
#end
#macro(delRelation2)
	#set($mtmList = $MU.findMtmList($model, $modelName))
	#foreach($mtm in $mtmList)
		#set($RelationItem = $CSU.getSimpleType($mtm.relation))
		#set($relationItem = $CSU.getVariable($RelationItem))
		#set($relationKey = $mtm.relationKey)
		#set($key = $mtm.key)
		this.${relationItem}DAO.deleteByProperty("${relationKey}", $key);

	#end
#end